package com.appview;

import com.util.Config;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by QiHuang on 2015/10/27.
 * 选择管理类型窗口
 */
public class ManagerSelect extends JFrame implements ActionListener {
    private JLabel jLabel;
    private JButton jButton1, jButton2;
    private JPanel jPanel1, jPanel2;
    public ManagerSelect() {

    }

    public void openView() {
        initComponent();
        jPanel1.add(jLabel, new FlowLayout(FlowLayout.CENTER));
        jPanel2.add(jButton1);
        jPanel2.add(jButton2);
        jPanel2.setLayout(new FlowLayout(FlowLayout.CENTER));
        add(jPanel1);
        add(jPanel2);
        setLayout(new GridLayout(2, 1));
        setTitle("请选择");
        setSize(400, 200);
        setVisible(true);
        setLocation(400, 200);
        setResizable(false);
        setAlwaysOnTop(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private void initComponent() {
        jLabel = new JLabel("请选择管理类型");
        jButton1 = new JButton("教师");
        jButton2 = new JButton("学生");

        jPanel1 = new JPanel();
        jPanel2 = new JPanel();

        initListener();
    }

    private void initListener() {
        jButton1.addActionListener(this);
        jButton2.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == jButton1) {
            Config.setType(0);//教师管理
            this.dispose();
        }else {
            Config.setType(1);//学生管理
        }
        MainView mainView = new MainView();
        mainView.openView();
        this.dispose();
    }
}
